<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch" data-options="{searchDatagrid:$.CurrentNavtab.find('#datagrid-product-list')}">
        <fieldset>
            <legend style="font-weight:normal;">页头搜索：</legend>
            <div style="margin:0; padding:1px 5px 5px;">
                <span>成品材料编号：</span>
                <input type="text" name="product_no" class="form-control" size="15">

                <span>产品名称：</span>
                <input type="text" name="product_name" class="form-control" size="15">

                <span>产品分类：</span>
                <select data-toggle="selectpicker" name="category_id">
                    <option value="">全部</option>
                    {!! $optionHtml !!}
                </select>

                <span>公共材料：</span>
                <select data-toggle="selectpicker" name="is_public">
                    <option value="">全部</option>
                    <option value="yes">是</option>
                    <option value="no">否</option>
                </select>

                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">开始搜索！</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table class="table table-bordered" id="datagrid-product-list" data-toggle="datagrid" data-options="{
        height: '100%',
        gridTitle : '产品列表',
        showToolbar: true,
        toolbarItem: 'export',
        editMode: 'dialog',
        local: 'remote',
        dataUrl: '/admin/pro/list',
        editUrl: '/admin/pro/save',
        delUrl: '/admin/pro/del',
        delPK: 'id',
        linenumberAll: true,
        sortAll: false,
        contextMenuH: true,
        contextMenuB: false,
        inlineEditMult: false,
        paging: {showPagenum:10, selectPageSize:'20,50,100', pageCurrent:1, pageSize:20},
        showEditbtnscol: false,
        customEditbtns: {width:200,position:'replace'},
        fullGrid: true,
        fieldSortable: false,
        filterThead: false,
        columnMenu: false,
        exportOption:{type:'file', options:{url:'admin/pro/export', type:'get', data: {_token : '{{ csrf_token() }}'}}}
    }">
        <thead>
        <tr>
            <th data-options="{name:'product_name',align:'center',width:100}">产品名称</th>
            <th data-options="{name:'img_url', render:'create_img_tag',align:'center',width:100}">产品图片</th>
            <th data-options="{name:'qrcode',align:'center',width:100}">产品二维码</th>
            <th data-options="{name:'product_no',align:'center',width:100}">产品编号</th>
            <th data-options="{name:'number',align:'center',width:100}">可用库存</th>
            <th data-options="{name:'warning_number',align:'center',width:100}">预警库存</th>
            <th data-options="{name:'full_number',align:'center',width:100}">库存充足数量</th>
            <th data-options="{name:'is_public', type:'select', items:is_public, align:'center',width:100}">公共材料</th>
            {{--<th data-options="{name:'barcode',align:'center',width:100}">条形码</th>--}}
            <th data-options="{name:'category_id', type:'select', items:datagrid_category, align:'center',width:300}">产品分类</th>
            <th data-options="{align:'center',width:300,render:product_manage}">操作</th>
        </tr>
        </thead>
    </table>
</div>
<script>
    function datagrid_category() {
        return [{!! $catejson !!}]
    }
    function is_public(){
        return [{'yes':'是'}, {'no':'否'}]
    }
    function create_img_tag(value){
        return '<img src="'+value+'" width="100" height="100">';
    }
    function create_qrcode(value){
        return '<img src = "data:image/png;base64, ' + value + '" width="100" height="100">';
    }
    function product_manage(value, data){
        html = '<button type="button" class="btn btn-green" data-toggle="dialog" data-options="{id:\'pro-attr-dialog\',fresh:true, url:\'/admin/pro/attr-list\', title:\'材料属性管理\',width:1000,height:1000, data:{product_id:' + data.id + '}}"><i class="fa fa-edit"></i> 属性</button>';

        html += '<button type="button" class="btn btn-green" data-toggle="dialog" data-options="{id:\'pro-edit-dialog\',fresh:true, url:\'/admin/pro/edit\', title:\'材料编辑\',width:1000,height:1000, data:{id:' + data.id + '}}"><i class="fa fa-edit"></i> 编辑</button>';

        html += '<button type="button" class="btn btn-green" data-toggle="dialog" data-options="{id:\'pro-purchase-dialog\',fresh:true, url:\'/admin/purchase/add\', title:\'材料采购\',width:1000,height:1000, data:{product_id:' + data.id + '}}"><i class="fa fa-edit"></i> 采购入库</button>';

        html += '<button type="button" class="btn btn-green" data-toggle="navtab" data-options="{id:\'pro-supplier-navtab\',fresh:true, url:\'/admin/pro/supplier-list\', title:\'材料供应商\',width:800,height:700, data:{product_id:' + data.id + '}}"><i class="fa fa-edit"></i> 供应商</button>';

        html += '<button type="button" class="btn-red" data-toggle="del.datagrid.tr">删除</button>';
        return html;
    }
</script>